﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace TransformBLG
{
    public class PerfItem
    {

        private static Regex headerRegEx = new Regex(@"^[\\]{2}(?<Computer>[a-zA-Z\d-$]+)[\\]{1}(?<Category>.+)[\\]{1}(?<Counter>.+)", RegexOptions.Compiled);
        private static Regex objectRegEx = new Regex(@"(?<object>.+)\((?<test>([^)]+))\)", RegexOptions.Compiled);

        /// <summary>
        /// Gets or sets the machine.
        /// </summary>
        /// <value>
        /// The machine.
        /// </value>
        public string Machine { get; set; }

        /// <summary>
        /// Gets or sets the object.
        /// </summary>
        /// <value>
        /// The object.
        /// </value>
        public string Object { get; set; }

        /// <summary>
        /// Gets or sets the instance.
        /// </summary>
        /// <value>
        /// The instance.
        /// </value>
        public string Instance { get; set; }

        /// <summary>
        /// Gets or sets the counter.
        /// </summary>
        /// <value>
        /// The counter.
        /// </value>
        public string Counter { get; set; }

        /// <summary>
        /// Gets or sets the date.
        /// </summary>
        /// <value>
        /// The date.
        /// </value>
        public string Date { get; set; }

        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>
        /// The value.
        /// </value>
        public string Value { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is valid item.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is valid item; otherwise, <c>false</c>.
        /// </value>
        public bool IsValidItem { get; set; }



        /// <summary>
        /// Initializes a new instance of the <see cref="PerfItem"/> class.
        /// </summary>
        /// <param name="headerString">The header string.</param>
        public PerfItem(string headerString) : base()
        {
            IsValidItem = true;

            Match regMatch = headerRegEx.Match(headerString);
            if(regMatch.Success)
            {
                Match objMatch = objectRegEx.Match(regMatch.Groups[2].Value);

                Machine = regMatch.Groups[1].Value;
                if(objMatch.Success)
                {
                    Object = objMatch.Groups[2].Value;
                    Instance = objMatch.Groups[3].Value;
                }
                else
                {
                    Object = regMatch.Groups[2].Value;
                    Instance = string.Empty;
                }
                
                
                Counter = regMatch.Groups[3].Value;
            }
            else
            {
                IsValidItem = false;
            }

        }
    }


}
